package com.dzzw.Servlet.DetailServlet;

import com.dzzw.Dao.DetailDao;
import com.dzzw.Model.Detail;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/View/DetailAddServlet")
public class DetailAddServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private final DetailDao detailDao = new DetailDao();
    public DetailAddServlet(){
        super();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        int vote_id = Integer.parseInt(request.getParameter("vote_id"));
        int option_id = Integer.parseInt(request.getParameter("option_id"));
        int user_id = Integer.parseInt(request.getParameter("user_id"));
        Detail detail = new Detail();
        detail.setVote_id(vote_id);
        detail.setOption_id(option_id);
        detail.setUser_id(user_id);
        detailDao.DetailAdd(detail);
        System.out.println("用户投票成功！");
        response.sendRedirect("/View/SelectAllVote.jsp");
    }
}
